Installing GLUT

If you don't have it already, you will need to install GLUT before you can follow the rest of the directions.

Download the GLUT libraries and header files here.  There's no installer, so you will have to put the files manually in places where the compiler will find them.  Assuming Developer Studio is in the standard places, put:

  1. glut.h in C:\Program Files\Microsoft Visual Studio\VC98\include\

  2. glut32.lib in c:\Program Files\Microsoft Visual Studio\VC98\lib

  3. glut32.dll in c:\windows\system32 (or c:\WINNT\system32, if you're running Windows NT/2000)

You should only have to do this once.

Writing an OpenGL program on Windows

This document will guide you through the steps needed to write an application that uses OpenGL on the Windows platform. We assume you're using Microsoft Visual Studio 6.0. If you're not, you should be able to adapt these instructions to suit your development environment.

  1. Start Visual Studio.
  2. Create a new project by selecting "New" from the "File" menu.
  3. Select "Win32 Console Application" from the list of choices, and give your project a name.
  4. Create an empty project.
  5. From the "Project" menu, choose "Settings...".
  6. Choose the "Link" tab.
  7. Add "opengl32.lib glu32.lib glut32.lib" to the end of the list of libraries.
  8. Click "OK".

Your project is now ready to use OpenGL, the GLU library, and the GLUT library. To test your setup, try the following:

  1. create a new C file called "test.c" by choosing "New" from the "File" menu and picking "C++ Source File".
  2. Type in the following code:
    
    #include <glut.h>
    
    void Display( void )
    {
    	glClearColor( 0, 0, 0, 1 );
    	glClear( GL_COLOR_BUFFER_BIT );
    	glMatrixMode( GL_PROJECTION );
    	glLoadIdentity();
    	glMatrixMode( GL_MODELVIEW );
    	glLoadIdentity();
    	glOrtho( 0, 1, 0, 1, -1, 1 );
    
    	glShadeModel( GL_SMOOTH );
    	glBegin( GL_QUADS );
    		glColor3f( 1, 0, 0 );
    		glVertex3f( 0, 0, 0 );
    		glColor3f( 0, 1, 0 );
    		glVertex3f( 0, 1, 0 );
    		glColor3f( 0, 0, 1 );
    		glVertex3f( 1, 1, 1 );
    		glColor3f( 1, 1, 1 );
    		glVertex3f( 1, 0, 0 );
    	glEnd();
    	glFlush();
    }
    
    int main( int argc, char *argv[] )
    {
    	glutInit( &argc, argv );
    	glutInitWindowSize( 300, 300 );
    	glutInitDisplayMode( GLUT_SINGLE | GLUT_RGBA );
    
    	glutCreateWindow( "Testing OpenGL!" );
    	glutDisplayFunc( Display );
    
    	glutMainLoop();
    	return 0;
    }
  3. Select "Build TestOpenGL.exe" from the "Build" menu (or press F7)

  4. Select "Go" from the "Debug" submenu of the "Build" menu (or prss F5)

You should see a window that looks like the following (minus the horrible JPEG artifacts):